﻿<script type="text/javascript">
    var toolbar_juese = [{
        text: '新增角色',
        iconCls: 'icon-add',
        handler: function() {
            $("#juese-edit").dialog('open');
            $("#jueSeID").val('');
            $("#info-juesequanxian").datalist('uncheckAll');
            $("#info-juesemingcheng").textbox('setValue', '');
        }
    }, '-', {
        text: '修改角色',
        iconCls: 'icon-edit',
        handler: function() {
            var curRow = $("#xinxi_juese").datagrid('getSelected');
            if (curRow) {
                $("#juese-edit").dialog('open');
                $("#info-juesequanxian").datalist('uncheckAll');
                $("#jueSeID").val(curRow.id);
                $("#info-juesemingcheng").textbox('setValue', curRow.juesemingcheng);
                var jueSeQuanXian = curRow.juesequanxian;
                var quanxian = $("#info-juesequanxian").datalist('getRows');

                for (var i = 0; i < quanxian.length; i++) {
                    if (jueSeQuanXian.indexOf(quanxian[i].quanxianmingcheng)>0) {
                        $("#info-juesequanxian").datalist('checkRow', i);
                    }
                }

            }
            else {
                alert("请选择要修改的角色信息。");
            }
        }
    }, '-', {
        text: '删除角色',
        iconCls: 'icon-remove',
        handler: function() {
            $("#juese-dlg").dialog('open');
        }
}];

        function DelJueSe() {
            var curRow = $("#xinxi_juese").datagrid('getSelected');
            if (curRow) {
                $.post('handler/xinxi_juese.ashx', { jueSeType: "3", jueSeID: curRow.id,uid:window.uid,kid:window.kid }, function(data, status) {
                    if (data == "OK") {
                        $("#juese-dlg").dialog('close');
                        $("#xinxi_juese").datagrid('load');
                        return;
                    }
                    if (data == "Failed") {
                        alert("删除角色信息失败，请重试");
                        $("#juese-dlg").dialog('close');
                        return;
                    }
                    alert(data);
                    $("#juese-dlg").dialog('close');
                });
            }
            else {
                alert("请选择要删除的角色信息。");
            }

        }
        function submitJueSeForm() {
            var juesemingcheng = $("#info-juesemingcheng").textbox('getText');
            if (juesemingcheng) {
                var checkQuanXian = $("#info-juesequanxian").datalist('getChecked');
                var jueSeQuanXian = "";
                for (var i = 0; i < checkQuanXian.length; i++) {
                    jueSeQuanXian = jueSeQuanXian + "[" + checkQuanXian[i].quanxianmingcheng + "]";
                }
                $.post('handler/xinxi_juese.ashx', { "jueSeType": $("#jueSeType").val(), "jueSeID": $("#jueSeID").val(), "info-juesemingcheng": juesemingcheng, "info-juesequanxian": jueSeQuanXian,uid:window.uid,kid:window.kid }, function(data, status) {
                    if (data == "OK") {
                        $("#xinxi_juese").datagrid('load');
                        $("#juese-edit").dialog('close');
                        return;
                    }
                    if (data == "Failed") {
                        alert("保存角色数据失败，请重试...");
                        $("#juese-edit").dialog('close');
                        return;
                    }
                    alert(data);
                });

            }
        }
        function clearJueSeForm() {
            $("#juese-edit").dialog('close');
        }
        $.parser.onComplete = function () {
            $("#xinxi_juese").datagrid({
                url: 'handler/xinxi_juese.ashx',
                method: 'post',
                queryParams: { jueSeType: '1' ,uid:window.uid,kid:window.kid}
            });
            $("#info-juesequanxian").datalist({
                url: 'handler/xinxi_quanxian.ashx',
                method: 'get',
                queryParams: {uid:window.uid,kid:window.kid}
            });
        }
</script>

<table id="xinxi_juese" style="width: 100%" class="easyui-datagrid" title="角色管理"
    data-options="border:false,singleSelect:true,collapsible:false,striped:true,toolbar:toolbar_juese,fitColumns:true, height: document.body.scrollHeight-90">
    <thead>
        <tr>
            <th data-options="field:'juesemingcheng'">
                角色名称
            </th>
            <th data-options="field:'juesequanxian'">
                角色权限
            </th>
            <th data-options="field:'id',hidden:true">
                编号
            </th>
        </tr>
    </thead>
</table>
<div id="juese-edit" class="easyui-dialog" title="角色信息编辑" data-options="modal:true,closed:true,iconCls:'icon-edit',draggable:false,collapsible:false,minimizable:false,maximizable:false,resizable:false"
    style="width: 500px; height: 450px; padding: 10px;">
    <div style="width: 350px; margin: 0 auto;">
        <table cellpadding="5" style="font-size: 13px; margin: 0 auto; padding-top: 20px">
            <tr>
                <td>
                    角色名称:
                </td>
                <td>
                    <input class="easyui-textbox" type="text" id="info-juesemingcheng" name="info-juesemingcheng"
                        data-options="width:200"></input>
                </td>
            </tr>
            <tr>
                <td valign="top">
                    角色权限:
                </td>
                <td>
                    <div class="easyui-datalist" id="info-juesequanxian" title="系统权限" style="width: 200px;
                        height: 250px" data-options="textField:'quanxianmingcheng',valueField:'id',checkbox: true,selectOnCheck: false,onBeforeSelect: function(){return false;}">
                    </div>
                </td>
            </tr>
        </table>
        <input type="hidden" name="jueSeType" id="jueSeType" value="2" />
        <input type="hidden" name="jueSeID" id="jueSeID" value="" />
        <div style="text-align: center; padding: 5px">
            <a href="javascript:void(0)" class="easyui-linkbutton" style="width: 75px" onclick="submitJueSeForm()"
                data-options="iconCls:'icon-ok'">保存</a> <a href="javascript:void(0)" class="easyui-linkbutton"
                    style="width: 75px" onclick="clearJueSeForm()" data-options="iconCls:'icon-cancel'">关闭</a>
        </div>
    </div>
</div>
<div id="juese-dlg" class="easyui-dialog" title="删除确认" style="width: 300px; height: 150px;
    padding: 10px" data-options="
				iconCls: 'icon-help',
				buttons: '#juse-dlg-buttons',
				modal:true,
				closed:true
			">
    确定要删除该角色信息吗？
</div>
<div id="juse-dlg-buttons">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:DelJueSe();">
        确定</a> <a href="javascript:void(0)" class="easyui-linkbutton" onclick="javascript:$('#juese-dlg').dialog('close')">
            取消</a>
</div>
